const {
  addChatNewsService,
  queryChatNewsServcie,
  queryGroupService,
  addGroupByIdService
} = require("../service/chat.service");
const {getUserInfo} = require("../service/user.service")
class ChatController {
  async addChatNewsControl(data) {
    const res = await addChatNewsService(data);
    return res.dataValues.id;
  }

  async queryChatNewsCtxControl(ctx, next) {
    let data = ctx.request.body || {};
    const res = await queryChatNewsServcie(data);
    ctx.body = {
      code: 200,
      data: res,
      message: "success",
    };
  }
  // websocket调用
  async queryChatNewsControl(data) {
    const res = await queryChatNewsServcie(data);
    return res[0].dataValues;
  }

  async queryGroupControl(ctx, next) {
    const res = await queryGroupService();
    ctx.body = {
        code:200,
        message:"success",
        data:res,
    }
  }


  async addChatGroupSocket(data) {
    let userId = data.userId;
    const item = await getUserInfo({id:userId})
    console.log(item,"userinfo")
    let requestObj = {
        id:data.id,
        title:item[0].nickname||item[0].username,
        titleImg:item[0].avatar,
    }
    const res = await addGroupByIdService(requestObj);
  }
}

module.exports = new ChatController();
